package com.manor.paradise.adapter

import android.graphics.Color
import android.widget.TextView
import com.blankj.utilcode.util.SpanUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.noober.background.drawable.DrawableCreator
import com.manor.common.utils.DpUtil
import com.manor.paradise.R
import com.manor.paradise.bean.Replacement
import java.math.BigDecimal


class ReplacementAdapter(layoutResId: Int, data: MutableList<Replacement.RecordsBean>?) : BaseQuickAdapter<Replacement.RecordsBean, BaseViewHolder>
(layoutResId, data) {


    override fun convert(helper: BaseViewHolder, item: Replacement.RecordsBean) {
        val tvCustomer = helper.getView<TextView>(R.id.tv_customer)
        val tvImg = helper.getView<TextView>(R.id.tv_img)

        helper.setText(R.id.tv_time, "时间：" + item.createTime)
                .setText(R.id.tv_deal, (if (item.type == 2) "换出米粒：" else "换入米粒：") + item.crystalOre)
                .setText(R.id.tv_state, (if (item.type == 2) "获得嗨券：" else "消耗嗨券：") + item.sdCoupons)

        SpanUtils.with(tvCustomer)
                .appendLine("单价")
                .append(item.unit.setScale(2, BigDecimal.ROUND_DOWN).toString() + "券")
                .setForegroundColor(Color.parseColor("#FF10DFF7"))
                .setFontSize(20, true)
                .create()


        if (item.type == 2) {
            tvImg.text = "换入嗨券"
            tvImg.background = DrawableCreator.Builder()
                    .setCornersRadius(DpUtil.dp2px(8).toFloat())
                    .setSolidColor(Color.parseColor("#FFE554A5"))
                    .build()

        } else {
            tvImg.text = "换入米粒"
            tvImg.background = DrawableCreator.Builder()
                    .setCornersRadius(DpUtil.dp2px(8).toFloat())
                    .setSolidColor(Color.parseColor("#FF1AA7CB"))
                    .build()
        }
    }

}